﻿function nowTime(){
    var date=new Date();
    var year=date.getFullYear();
    var month=(date.getMonth()+1)>9?(date.getMonth()+1):"0"+(date.getMonth()+1);
    var day=(date.getDate())>9?(date.getDate()):"0"+(date.getDate());
    return year+"/"+month+"/"+day;
 }
function startTime(){
    var date=new Date();
    var preDate = new Date(date.getTime() - 30*24*60*60*1000);
    var year=preDate.getFullYear();
    var month=(preDate.getMonth()+1)>9?(preDate.getMonth()+1):"0"+(preDate.getMonth()+1);
    var day=(preDate.getDate())>9?(preDate.getDate()):"0"+(preDate.getDate());
    return year+"/"+month+"/"+day;
 }


 function getRootPath() {
	 return "http://yddcft.cpic.com.cn//ydck/";
  }

 function getUrlPara(paraName){
	var sUrl  =  location.href; 
	var sReg  =  "(?:\\?|&){1}"+paraName+"=([^&]*)" ;
	var re=new RegExp(sReg,"gi"); 
	re.exec(sUrl); 
	return RegExp.$1;
}

function getId(obj){
	return document.getElementById(obj);
}

function tip(mess){
	
	var t=document.createElement("div"),
	s=document.createElement("span");
	t.appendChild(s);
	t.className="toast";
	s.innerHTML=mess;
	s.style.textAlign='center';
	document.body.appendChild(t);
	setTimeout(function(){
		document.body.removeChild(t);
	},1500);
		
}

function getImg(con,data){
	if(navigator.userAgent.match(/Android/i)) { 
		window.mck.showSelectFilePop(con,data);
	}else if(navigator.userAgent.match(/iPhone/i)){
		window.location.href="ios://getImage:"+con+":"+data;
	}
	
}

function loading(obj,con){
	document.body.style.overflow="hidden";
	var scrollY=document.body.scrollTop;
	//console.log(scrollY);
	document.body.addEventListener('touchmove', function (event) {
		if(document.body.style.overflow=="hidden")
			event.preventDefault();
	}, false);

	var div=document.createElement("div");
	div.className="model_bg";
	div.style.top=scrollY+"px";

	var div2=document.createElement("div");
	div2.className="model_m";

	var div3=document.createElement("div");
	div3.className="model_main";

	var div4=document.createElement("div");
	div4.className="model_mess";
	div4.innerHTML=con;

	var load=document.getElementById(obj);
	load.innerHTML="<span class='icon-spin4 animate-spin'></span>";

	div3.appendChild(load);
	div3.appendChild(div4);
	div2.appendChild(div3);
	div.appendChild(div2);
	document.body.appendChild(div);
};

function model(val,btn){
	
	var scrollY=document.body.scrollTop;

	var div=document.createElement("div");
	div.className="model_bg";
	div.style.top=scrollY+"px";


	var div2=document.createElement("div");
	div2.className="model_m";

	var div3=document.createElement("div");
	div3.className="model_con1";
	div3.style.height=winSize().height-30+"px";

	var textarea=document.createElement("textarea");
	textarea.id="mtext";
	textarea.style.width="100%";
	textarea.style.height=(winSize().height-30-80)+"px";
	textarea.style.overflow="auto";
	textarea.value=val;

	if(btn=="关闭")
		textarea.readOnly="readonly";
	
	
	var button=document.createElement("button");
	button.id="mbtn";
	button.innerHTML=btn;

	div3.appendChild(textarea);
	div3.appendChild(button);
	div2.appendChild(div3);
	div.appendChild(div2);
	document.body.appendChild(div);

	return [div,button,textarea];
		
}

function mess(tit,content){
	document.body.style.overflow="hidden";
	var scrollY=document.body.scrollTop;

	document.body.addEventListener('touchmove', function (event) {
		if(document.body.style.overflow=="hidden")
			event.preventDefault(); 
	}, false);

	var div=document.createElement("div");
	div.className="mess_bg";
	div.style.top=scrollY+"px";

	var div2=document.createElement("div");
	div2.className="mess_m";

	var div3=document.createElement("div");
	div3.className="mess_main";

	var title=document.createElement("div");
	title.className="mess_t";
	title.innerHTML=tit;

	var con=document.createElement("div");
	con.className="mess_con";
	con.innerHTML=content;

	var btn=document.createElement("button");
	btn.innerHTML="确 认";
	btn.id="messbtn";

	div3.appendChild(title);
	div3.appendChild(con);
	div3.appendChild(btn);
	div2.appendChild(div3);
	div.appendChild(div2);
	document.body.appendChild(div);
	
	var fn;
	if(arguments[2] && typeof arguments[2]=="function"){
		fn=arguments[2];
	}
	
	btn.addEventListener("click",function(){
		document.body.style.overflow="auto";
		document.body.removeChild(div);
		if(typeof fn=="function"){
			fn();
		}
	});

}




function clearNoNum(obj){ 

    obj.value = obj.value.replace(/[^\d.]/g,""); 
    obj.value = obj.value.replace(/^\./g,""); 
    obj.value = obj.value.replace(/\.{2,}/g,"."); 
    obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$","."); 
} 

function checkNum(obj){  
    obj.value = obj.value.replace(/\.$/g,""); 
    if(obj.value=="")
		obj.value=0;
} 

function clearLastTrim(obj){
	obj.value = obj.value.replace(/^\s/g,""); 
	obj.value = obj.value.replace(" ","$#$").replace(/\s/g,"").replace("$#$"," "); 
	obj.value = obj.value.replace(/\s$/g,""); 
}

var winSize = function() {
    var e = window,
        a = 'inner';
 
    if (!('innerWidth' in window )){
        a = 'client';
        e = document.documentElement || document.body;
    }
 
    return { width : e[ a+'Width' ],height:e[a+'Height']};
};

//验证身份证号的函数
 function verification(val) {
	 var reg = /^(\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$/;
	 return reg.test(val);

 }
//验证姓名
function CheckChinese(val) {
	var reg = /^[\u4e00-\u9fa5]{1}\s[\u4e00-\u9fa5]{1,2}$/;
	return reg.test(val);
 }
